package com.ruoyi.fileMaintenance.api;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.fileMaintenance.domain.TCourseLearning;
import com.ruoyi.fileMaintenance.domain.TLearningMaterials;
import com.ruoyi.fileMaintenance.domain.dto.TCourseDto;
import com.ruoyi.fileMaintenance.domain.dto.TLearningMaterialsDto;
import com.ruoyi.fileMaintenance.service.ITCourseService;
import com.ruoyi.fileMaintenance.service.ITLearningMaterialsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 学习资料Controller
 * 
 * @author ruoyi
 * @date 2024-03-27
 */
@Api("app接口")
@RestController
@RequestMapping("/app_api")
public class appApiController extends BaseController
{

    @Autowired
    private ITCourseService tCourseService;

    @Autowired
    private ITLearningMaterialsService tLearningMaterialsService;

    /**
     * 查询课程列表接口-可
     */
    @ApiOperation("查询课程列表")
    @GetMapping("/courseList")
    public TableDataInfo courseList(TCourseDto tCourseDto)
    {
        startPage();
        List<TCourseDto> list = tCourseService.selectTCourseList2(tCourseDto);
        return getDataTable(list);
    }

    /**
     * 课程重新学习接口-可
     */
    @ApiOperation("课程重新学习")
    @GetMapping("/courseRelearn/{id}")
    public AjaxResult courseRelearn(@ApiParam(value = "课程id", required = true)@PathVariable("id") Long courseId)
    {
        return toAjax(tCourseService.courseRelearn(courseId));
    }

    /**
     *  用户课程绑定接口-可
     */
    @ApiOperation("用户课程绑定")
    @PostMapping("/insertCourseBinding/{id}")
    public AjaxResult insertCourseBinding(@ApiParam(value = "课程id", required = true)@PathVariable("id") Long courseId)
    {
        return toAjax(tCourseService.insertCourseBinding(courseId));
    }

    /**
     *  查用户绑定课程-可
     */
    @ApiOperation("查用户绑定课程")
    @GetMapping("/selectCourseBinding")
    public AjaxResult selectCourseBinding()
    {
        return success(tCourseService.selectCourseBinding());
    }


    /**
     *  查询课程-单词 -可
     */
    @ApiOperation("查询课程-单词 type:1-全部，2-已学，3-未学")
    @GetMapping("/learningMaterialsList")
    public TableDataInfo learningMaterialsList(TLearningMaterialsDto tLearningMaterialsDto) {
        startPage();
        List<TLearningMaterials> list = tLearningMaterialsService.selectTLearningMaterialsList2(tLearningMaterialsDto);
        return getDataTable(list);
    }

    /**
     *  随机查课程下未学单词 1条数据-可
     */
    @ApiOperation("随机查课程下未学单词 1条数据")
    @GetMapping("/learningMaterialsList/{id}")
    public AjaxResult learningMaterialsList(@ApiParam(value = "课程id", required = true)@PathVariable("id") Long courseId)
    {
        return success(tLearningMaterialsService.selectUnlearnedTLearningMaterials(courseId));
    }

    /**
     *  查询学习资料详情接口-可
     */
    @ApiOperation("查询学习资料详情")
    @GetMapping(value = "learningMaterials/{id}")
    public AjaxResult getInfo(@ApiParam(value = "学习资料id", required = true)@PathVariable("id") Long id)
    {
        return success(tLearningMaterialsService.selectTLearningMaterialsById(id));
    }

    /**
     *  课程学习情况添加接口-可
     */
    @ApiOperation("课程学习情况添加")
    @PostMapping("/insertCourseLearning")
    public AjaxResult insertCourseLearning(@RequestBody TCourseLearning tCourseLearning)
    {
        return toAjax(tLearningMaterialsService.insertCourseLearning(tCourseLearning));
    }

    /**
     *  单词测试接口
     */
    @ApiOperation("单词测试")
    @GetMapping("/learningMaterialsTest")
    public TableDataInfo learningMaterialsTest(TLearningMaterials tLearningMaterials)
    {
        startPage();
        List<TLearningMaterials> list = tLearningMaterialsService.learningMaterialsTest(tLearningMaterials);
        return getDataTable(list);
    }
}
